package com.pay.plat.controller;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import com.pay.entity.BaseInfo;
import com.pay.entity.CashRule;
import com.pay.plat.annotation.AuthResource;
import com.pay.plat.mapping.MappingUtils;
import com.pay.service.IBaseInfoService;
import com.pay.service.ICashRuleService;
import com.pay.utils.ResponseData;

@Controller
public class SystemController {


	@Autowired
	private IBaseInfoService baseInfoService ;
	
	@Autowired
	private ICashRuleService cashRuleService ;

	@AuthResource
	@RequestMapping(value=MappingUtils.showSystemBase)
	public ModelAndView showSystemBase(Integer loginId) {
		List<BaseInfo> infoList = baseInfoService.list(null);
		ModelAndView m = new ModelAndView(MappingUtils.showSystemBase);
		m.addObject("infoList", infoList) ;
		m.addObject("loginId", loginId) ;
		return m ;
	}

	@AuthResource
	@ResponseBody
	@RequestMapping(value=MappingUtils.doEditSystemBase,method= {RequestMethod.POST})
	public ResponseData doEditSystemBase(BaseInfo baseInfo) {
		baseInfoService.updateValByKey(baseInfo) ;
		return ResponseData.ok() ;
	}
	
	@AuthResource
	@RequestMapping(value=MappingUtils.showCashRule)
	public ModelAndView showCashRule(Integer loginId) {
		CashRule cashRule = cashRuleService.getOne(null);
		ModelAndView m = new ModelAndView(MappingUtils.showCashRule);
		m.addObject("cashRule", cashRule) ;
		m.addObject("loginId", loginId) ;
		return m ; 
	}
	
	@AuthResource
	@ResponseBody
	@RequestMapping(value=MappingUtils.doCashRuleEdit,method= {RequestMethod.POST})
	public ResponseData doCashRuleEdit(CashRule cashRule) {
		return cashRuleService.doCashRuleEdit(cashRule) ;
	}
}
